from openai import OpenAI
from config import openai_api_key

# OpenAI Client
openai_client = OpenAI(api_key=openai_api_key, base_url="https://qianfan.baidubce.com/v2")

# 简单情绪打分
def score_sentiment(text):
    positive_keywords = ['上涨', '利好', '超预期', '回暖', '创新高']
    negative_keywords = ['暴跌', '利空', '下滑', '裁员', '危机']
    score = 0
    for word in positive_keywords:
        if word in text:
            score += 1
    for word in negative_keywords:
        if word in text:
            score -= 1
    return score

# 文章摘要生成
def summarize_articles(text):
    completion = openai_client.chat.completions.create(
        model="deepseek-v3",
        messages=[
            {"role": "system", "content": "你是一名专业财经研究助理，请将以下新闻内容提炼成机构投资要点。"},
            {"role": "user", "content": text}
        ]
    )
    return completion.choices[0].message.content.strip() 